/** layuiAdmin.std-v1.2.0 LPPL License By http://www.layui.com/admin/ */
 ;layui.define(["admin","table","util"],
    function(e){
     var t=layui.$,i=(layui.admin,layui.table),
         l=(layui.element,{
             all: {text:"留言",id:"LAY-app-message-all"},
             direct:{text:"文章评论",id:"LAY-app-message-direct"}}),
         a=function(e){return'<a href="detail?id='+e.id+'">'+e.message},
         b=function(e){return'<a href="pinglun?id='+e.id+'">'+e.message}
     ;
     i.render({
         elem:"#LAY-app-message-all",
         url:"getleave",
         page:!0,cols:[[{type:"checkbox",fixed:"left"},
             {field:"name",title:"姓名",width:120},
             {field:"contact",title:"内网IP",width:135},
             {field:"mip",title:"公网IP",width:135},
             {field:"message",title:"内容",minWidth:200,templet:a},
             {field:"isvread",title:"是否未读",templet:"#buttonIsTop",width:60,align:"center",sort:0},
             {field:"rtime",title:"留言时间",width:170}]],
         skin:"line"});


        i.render({
            elem:"#LAY-app-message-direct",
            url:"getcomment",
            page:!0,cols:[[{type:"checkbox",fixed:"left"},
                {field:"name",title:"姓名",width:110},
                {field:"contact",title:"内网IP",width:130},
                {field:"mip",title:"公网IP",width:130},
                {field:"title",title:"文章标题",minWidth:140},
                {field:"message",title:"内容",minWidth:200,templet:a},
                {field:"isvread",title:"是否未读",templet:"#buttonIsTop",width:60,align:"center",sort:0},
                {field:"rtime",title:"评论时间",width:170}]],
            skin:"line"});

     var d={del:function(e,t){
         var a=l[t],d=i.checkStatus(a.id),s=d.data;
         return 0===s.length?layer.msg("未选中行"):void layer.confirm("确定删除选中的数据吗？",
             function(){
             var id="";
             for(var d=0;d<s.length;d++){
                 id+=s[d]['id']+",";
             }
             id=id.substr(0,id.length-1);
                 layui.$.ajax({
                     type:'get',
                     dataType:"json",
                     url:'deleteleave/id/'+id,
                     success:function (data) {
                         layer.msg('删除成功',{icon:1})
                     },
                     error:function () {
                         layer.msg('删除失败', {icon: 2});
                     }
                 });

                 i.reload(a.id)
            })
         },
         ready:function(e,t){
         var a=l[t],d=i.checkStatus(a.id),
             s=d.data;
         return 0===s.length?layer.msg("未选中行"):(layer.msg("标记已读成功",{icon:1}),
             void i.reload(a.id))},readyAll:function(e,t){
         var i=l[t];layer.msg(i.text+"：全部已读",{icon:1})}};
     t(".LAY-app-message-btns .layui-btn").on("click",function(){
         var e=t(this),i=e.data("events"),
             l=e.data("type");
         d[i]&&d[i].call(this,e,l)}),e("message",{

     })});